package awd.bj.jls.webs.api.hystrix;

import awd.bj.jls.webs.api.DictionaryApi;
import awd.bj.jls.webs.utils.PagerResult;
import awd.bj.jls.webs.utils.QueryParam;
import awd.bj.jls.webs.utils.ResponseMessage;
import awd.bj.manager.model.DictionaryModel;
import feign.hystrix.FallbackFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @program: awd.bj.kss
 * @description:
 * @author: WS
 * @create: 2019-01-17
 **/
@Component("dictionaryApi")
public class DictionaryApiFallBackFactory implements FallbackFactory<DictionaryApi> {

    public static Logger logger = Logger.getLogger(DictionaryApi.class);


    @Override
    public DictionaryApi create(Throwable throwable) {
        return new DictionaryApi() {
            @Override
            public ResponseMessage<List<DictionaryModel>> list(Map<String, String[]> map) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<List<DictionaryModel>> getByField(String filed) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<List<Map<String, Object>>> getAllFields() {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<PagerResult<DictionaryModel>> getPageByfields(QueryParam qParam) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<DictionaryModel> getByid(String id) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<String> save(DictionaryModel dictionaryModel) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<String> saveorupdate(DictionaryModel dictionaryModel) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<String> update(String id, DictionaryModel dictionaryModel) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

            @Override
            public ResponseMessage<PagerResult<DictionaryModel>> query(Map<String, String[]> params) {
                throwable.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResponseMessage.ok();
            }

        };
    }
}
